package com.platform.system.mqtt.utils;

import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mqtt")
public class MqttTestController {

    @Autowired
    private MqttServiceImpl mqttService;

    @PostMapping("/publish")
    public String publishMessage(@RequestParam String clientId,
                                 @RequestParam String topic,
                                 @RequestParam String message) {
        mqttService.publishToClient(Lists.newArrayList(clientId), topic, message);
        return "Message sent to " + clientId;
    }
}
